/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package researchgrants.parts.LoggedData;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author DOStudent1
 */
public class LogableObjectsManager {

    public static String logableObjectToLoggedString(LogableObject logableObject) {
        String res="";
        
        LoggedLogableObject myLoggedObject=logableObject.toLoggedMyObject();
        String objectValue=myLoggedObject.toLoggedValue();

        res=logableObject.toLoggedMyObject().getClass().getSimpleName() + ";" + objectValue;

        return(res);
    }

    public static LogableObject loggedStringToLogableObject(String value) {
        LoggedLogableObject loggedMyObject=null;

        try {
            String valueClass=value.substring(0, value.indexOf(";"));
            String valueObject=value.substring(value.indexOf(";")+1);
            Class specificClass=Class.forName("javaapplication4." + valueClass);
            LoggedLogableObject tmpLoggedMyObject=(LoggedLogableObject)(specificClass.newInstance());
            loggedMyObject=tmpLoggedMyObject.fromLoggedValue(valueObject);
        }
        catch (InstantiationException ex) {
            Logger.getLogger(LogableObjectsManager.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(LogableObjectsManager.class.getName()).log(Level.SEVERE, null, ex);
        }        catch (ClassNotFoundException ex) {
            Logger.getLogger(LogableObjectsManager.class.getName()).log(Level.SEVERE, null, ex);
        }
        LogableObject logableObject = loggedMyObject.toLogableObject();
        return(logableObject);
    }
    
}
